package com.example.geekbanglinkedlist;

/**
 * @author zoRRo
 * @date 2020/11/14
 **/
public class Linked<T> {
    
    T val;
    
    Linked next;
    
    Linked(T x) {
        val = x;
    }
    
    public void add(int newval) {
        Linked node = new Linked(newval);
        if (this.next == null) {
            this.next = node;
        } else {
            this.next.add(newval);
        }
    }
    
    public Linked getNext() {
        return next;
    }
    
    public void print() {
        System.out.print(this.val);
        if (this.next != null) {
            System.out.print("-->");
            this.next.print();
        }
    }
}
